]>
git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/Tests/BATS Scripts/bats_test_proxy.sh
6 # Copyright (c) 2019 Apple Inc. All rights reserved.
8 # tests whether the state dump will create at most MAX_NUM_DUMP_FILES, to avoid wasting too much space.
9 base_test
="dnssdutil dnsquery -s 127.0.0.1 -n apple.com -t a"
11 # Enable the proxy and test over TCP
12 function test_proxy_tcp
{
13 test_proxy_on
$base_test --tcp
17 # Enable the proxy and test over UDP
18 function test_proxy_udp
{
19 test_proxy_on
$base_test
23 # Test the proxy over TCP without enabling it (should fail)
24 function test_noproxy_tcp
{
25 test_proxy
$base_test --tcp
32 # Test the proxy over UDP without enabling it (should fail)
33 function test_noproxy_udp
{
41 function test_proxy_on
{
42 local command_line
="$*"
46 dnssdutil dnsproxy
-i lo0
&
47 local dnssdutil_pid
=$
!
51 local dnssdutil_pid_now
=$(ps xa |sed -n -e 's/^ *\([0-9][0-9]*\).
*$
/\
1/' -e "/$dnssdutil_pid/p")
52 if [ $dnssdutil_pid != "$dnssdutil_pid_now" ]; then
53 echo "Failed to enable DNS proxy $dnssdutil_pid $dnssdutil_pid_now."
57 test_proxy $command_line
60 # Disable the proxy and wait for that to finish
61 kill -HUP $dnssdutil_pid
67 local command_line="$*"
69 # Try to do the DNS lookup
70 local output=$($command_line |egrep "^End reason:")
71 if [ "$output" = "End reason: received response" ]; then
72 echo "Proxy is working: $output"
75 echo "Proxy is not working: $output"
81 # Functions are put inside an array, use ($test) to evaluate it
82 declare -a tests=("test_proxy_tcp"
87 echo "----Proxy Test Start, $(date)----"
88 for test in "${tests[@]}"; do
91 if [[ $? -eq 0 ]]; then
92 echo "passed"$'\n' # use $'\n' to print one more newline character
98 echo "----Proxy Test End, $(date)----"
104 # indent-tabs-mode: nil